package orest.back.inforecommend;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import orest.back.userneeds.UserNeedsHandler;
import orest.front.achieve.AchieveHandler;




import net.ssta.common.Constants;
import net.ssta.core.base.ServletBase;
import net.ssta.core.db.DBConnectionProvider;
import net.ssta.core.db.DataBaseExecutor;
import net.ssta.core.db.PagingInfo;
import net.ssta.core.db.RecordSet;
import net.ssta.core.db.Record;
import net.ssta.core.web.RequestKit;

public class InfoRecommendServlet extends ServletBase {

	protected void defaultAction(HttpServletRequest request, HttpServletResponse response) throws IOException
	{
			System.out.println("UserNeedsServlet default Action");
	}
	
	
	
	/**
     * 获取成果信息列表
     * 
     * @param request
     * @param response
     */
    public void kjcgInfoList(HttpServletRequest request,
        HttpServletResponse response)
    {
    	try {
			try {
				
				RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
		        PagingInfo pagingInfo = new PagingInfo(request, 10, "^(?!.*(result)|(LTPAToken)).*$");
		        
		        Record searchRcd = requestKit.getRecordWithPrefix("");
		        
		        Map fildOptionMap = new HashMap();
		        
		        UserNeedsHandler unhandler = new UserNeedsHandler();
		        InfoRecommendHandler infoRecom = new InfoRecommendHandler();
		        RecordSet kjcgInfoSet = infoRecom.kjcgInfoList(requestKit, pagingInfo);
		        
		        
		        //成果类别
		        RecordSet cglb = AchieveHandler.getNewEnergyClassList(); 
		        for(int i=0;i<cglb.size();i++){
		        	Record rec =cglb.get(i);
		        	fildOptionMap.put("ITEM_CGLB"+rec.getString("OPTIONVALUE","").trim(),rec.getString("OPTIONNAME",""));
		        }
		        
		        
		        /*
		        //成果水平
		        RecordSet cgsp = unhandler.getZdxx("ITEM_2");
		        for(int i=0;i<cgsp.size();i++){
		        	Record rec =cgsp.get(i);
		        	fildOptionMap.put("KJCG_ITEM_2"+rec.getString("XXDM",""),rec.getString("XXMC",""));
		        }
		        
		        //所处阶段
		        RecordSet scjd = unhandler.getZdxx("ITEM_16");
		        for(int i=0;i<scjd.size();i++){
		        	Record rec =scjd.get(i);
		        	fildOptionMap.put("KJCG_ITEM_16"+rec.getString("XXDM",""),rec.getString("XXMC",""));
		        }
		        
		        
		      //所属科技计划
		        RecordSet kjjh = unhandler.getZdxx("ITEM_140");
		        for(int i=0;i<kjjh.size();i++){
		        	Record rec =kjjh.get(i);
		        	fildOptionMap.put("KJCG_ITEM_140"+rec.getString("XXDM",""),rec.getString("XXMC",""));
		        }
		        
		        
		        
		        //获得所有省份的map
		        Map provinceMap = new HashMap();
		        RecordSet provinceSet = unhandler.getAllProvince();
		        for(int i=0;i<provinceSet.size();i++){
		        	Record rcd = provinceSet.get(i);
		        	provinceMap.put(rcd.getString("PROVINCE_ID",""), rcd.getString("PROVINCE_NAME",""));
		        }
		        */
		        
		        request.setAttribute("pagingInfo", pagingInfo);
		        request.setAttribute("kjcgInfoSet", kjcgInfoSet);
		        request.setAttribute("cglb", cglb);
//		        request.setAttribute("cgsp", cgsp);
//		        request.setAttribute("scjd", scjd);
//		        request.setAttribute("kjjh", kjjh);
		        
		        request.setAttribute("fildOptionMap", fildOptionMap);
//		        request.setAttribute("provinceMap", provinceMap);
		        
		        request.setAttribute("searchRcd", searchRcd);
		        
				
				forward("/back/infoRecommend/KjcgRecommend.jsp");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (ServletException e) {
			e.printStackTrace();
		}
    }
    
    
    
    
    
    
    /**
     * 科技成果推荐
     * 
     * @param request
     * @param response
     */
    public void changeKjcgStatus(HttpServletRequest request,
        HttpServletResponse response)
    {
		RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
		InfoRecommendHandler infoRecommhandler = new InfoRecommendHandler();
        infoRecommhandler.changeKjcgStatus(requestKit);
    }
    
    
    
    
    
     
    /**
     * 获取专家信息列表,用于专家照片信息维护
     * 
     * @param request
     * @param response
     */
    public void ExpertPhotoMaintainList(HttpServletRequest request,HttpServletResponse response)
    {
    	try {
			try {
				
				RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
		        PagingInfo pagingInfo = new PagingInfo(request, 10, "^(?!.*(result)|(LTPAToken)).*$");
		        
		        Record searchRcd = requestKit.getRecordWithPrefix("");
		        
		        Map fildOptionMap = new HashMap();
		        
		        UserNeedsHandler unhandler = new UserNeedsHandler();
		        InfoRecommendHandler infoRecom = new InfoRecommendHandler();
		        RecordSet expertInfoSet = infoRecom.ExpertInfoList(requestKit, pagingInfo);
		        
		        //性别
		        RecordSet sex = unhandler.getZdxx("ITEM_181");
		        for(int i=0;i<sex.size();i++){
		        	Record rec =sex.get(i);
		        	fildOptionMap.put("ITEM_181"+rec.getString("XXDM",""),rec.getString("XXMC",""));
		        }
		        
		        //获得所有省份的map
		        Map provinceMap = new HashMap();
		        RecordSet provinceSet = unhandler.getAllProvince();
		        for(int i=0;i<provinceSet.size();i++){
		        	Record rcd = provinceSet.get(i);
		        	provinceMap.put(rcd.getString("PROVINCE_ID",""), rcd.getString("PROVINCE_NAME",""));
		        }
		        
		        request.setAttribute("pagingInfo", pagingInfo);
		        request.setAttribute("expertInfoSet", expertInfoSet);
		        request.setAttribute("sex", sex);
		        
		        request.setAttribute("fildOptionMap", fildOptionMap);
		        request.setAttribute("searchRcd", searchRcd);
		        request.setAttribute("provinceSet", provinceSet);
		        request.setAttribute("provinceMap", provinceMap);
				forward("/back/infoRecommend/ExpertPhotoMaintain.jsp");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (ServletException e) {
			e.printStackTrace();
		}
    }
    
    
    
    
    
    
    
    /**
     * 获取专家信息列表
     * 
     * @param request
     * @param response
     */
    public void ExpertInfoList(HttpServletRequest request,
        HttpServletResponse response)
    {
    	try {
			try {
				
				RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
		        PagingInfo pagingInfo = new PagingInfo(request, 10, "^(?!.*(result)|(LTPAToken)).*$");
		        
		        Record searchRcd = requestKit.getRecordWithPrefix("");
		        
		        Map fildOptionMap = new HashMap();
		        
		        UserNeedsHandler unhandler = new UserNeedsHandler();
		        InfoRecommendHandler infoRecom = new InfoRecommendHandler();
		        RecordSet expertInfoSet = infoRecom.ExpertInfoList(requestKit, pagingInfo);
		        
		        //性别
		        RecordSet sex = unhandler.getZdxx("ITEM_181");
		        for(int i=0;i<sex.size();i++){
		        	Record rec =sex.get(i);
		        	fildOptionMap.put("ITEM_181"+rec.getString("XXDM",""),rec.getString("XXMC",""));
		        }
		        
		        //获得所有省份的map
		        Map provinceMap = new HashMap();
		        RecordSet provinceSet = unhandler.getAllProvince();
		        for(int i=0;i<provinceSet.size();i++){
		        	Record rcd = provinceSet.get(i);
		        	provinceMap.put(rcd.getString("PROVINCE_ID",""), rcd.getString("PROVINCE_NAME",""));
		        }
		        
		        request.setAttribute("pagingInfo", pagingInfo);
		        request.setAttribute("expertInfoSet", expertInfoSet);
		        request.setAttribute("sex", sex);
		        
		        request.setAttribute("fildOptionMap", fildOptionMap);
		        request.setAttribute("searchRcd", searchRcd);
		        request.setAttribute("provinceSet", provinceSet);
		        request.setAttribute("provinceMap", provinceMap);
				forward("/back/infoRecommend/ExpertRecommend.jsp");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (ServletException e) {
			e.printStackTrace();
		}
    }
    
    
    
    
    /**
     * 科研专家排序
     * 
     * @param request
     * @param response
     */
    public void ExpertSort(HttpServletRequest request,
        HttpServletResponse response)
    {
    	try {
			try {
				
				RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
		        PagingInfo pagingInfo = new PagingInfo(request, 10, "^(?!.*(result)|(LTPAToken)).*$");
		        
		        Record searchRcd = requestKit.getRecordWithPrefix("");
		        
		        Map fildOptionMap = new HashMap();
		        
		        UserNeedsHandler unhandler = new UserNeedsHandler();
		        InfoRecommendHandler infoRecom = new InfoRecommendHandler();
		        RecordSet expertInfoSet = infoRecom.ExpertInfoList(requestKit, pagingInfo);
		        
		        //性别
		        RecordSet sex = unhandler.getZdxx("ITEM_181");
		        for(int i=0;i<sex.size();i++){
		        	Record rec =sex.get(i);
		        	fildOptionMap.put("ITEM_181"+rec.getString("XXDM",""),rec.getString("XXMC",""));
		        }
		        
		        //获得所有省份的map
		        Map provinceMap = new HashMap();
		        RecordSet provinceSet = unhandler.getAllProvince();
		        for(int i=0;i<provinceSet.size();i++){
		        	Record rcd = provinceSet.get(i);
		        	provinceMap.put(rcd.getString("PROVINCE_ID",""), rcd.getString("PROVINCE_NAME",""));
		        }
		        
		        request.setAttribute("pagingInfo", pagingInfo);
		        request.setAttribute("expertInfoSet", expertInfoSet);
		        request.setAttribute("sex", sex);
		        
		        request.setAttribute("fildOptionMap", fildOptionMap);
		        request.setAttribute("searchRcd", searchRcd);
		        request.setAttribute("provinceSet", provinceSet);
		        request.setAttribute("provinceMap", provinceMap);
				forward("/back/infoRecommend/ExpertSort.jsp");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (ServletException e) {
			e.printStackTrace();
		}
    }
    
    
    
    
    
    
    
    /**
     * 设置推荐到频道的专家的排序号
     * 
     * @param request
     * @param response
     */
    public void setSortNum(HttpServletRequest request,
        HttpServletResponse response)
    {
		RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
		InfoRecommendHandler infoRecommhandler = new InfoRecommendHandler();
		String tableName = requestKit.getParameter("tableName", "");
		String uuidFiledName = requestKit.getParameter("uuidFiledName", "");
		String uuid = requestKit.getParameter("uuid", "");
		String sortField = requestKit.getParameter("sortField", "");
		String sortNum = requestKit.getParameter("sortNum", "");
		
        infoRecommhandler.setSortNum(tableName,uuidFiledName,uuid,sortField,sortNum);
    }
    
    
    
    
    
    /**
     * 设置推荐到
     * 
     * @param request
     * @param response
     */
    public void changeExpertStatus(HttpServletRequest request,
        HttpServletResponse response)
    {
		RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
		InfoRecommendHandler infoRecommhandler = new InfoRecommendHandler();
        infoRecommhandler.changeExpertStatus(requestKit);
    }
    
    
    
    
    
    /**
     * 获取单位信息列表
     * 
     * @param request
     * @param response
     */
    public void unitInfoList(HttpServletRequest request,
        HttpServletResponse response)
    {
    	try {
			try {
				
				RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
		        PagingInfo pagingInfo = new PagingInfo(request, 10, "^(?!.*(result)|(LTPAToken)).*$");
		        
		        Record searchRcd = requestKit.getRecordWithPrefix("");
		        
		        Map fildOptionMap = new HashMap();
		        
		        UserNeedsHandler unhandler = new UserNeedsHandler();
		        InfoRecommendHandler infoRecom = new InfoRecommendHandler();
		        RecordSet unitInfoSet = infoRecom.unitInfoList(requestKit, pagingInfo);
		        
		        
		        //获得所有省份的map
		        Map provinceMap = new HashMap();
		        RecordSet provinceSet = unhandler.getAllProvince();
		        for(int i=0;i<provinceSet.size();i++){
		        	Record rcd = provinceSet.get(i);
		        	provinceMap.put(rcd.getString("PROVINCE_ID",""), rcd.getString("PROVINCE_NAME",""));
		        }
		        
		        request.setAttribute("pagingInfo", pagingInfo);
		        request.setAttribute("unitInfoSet", unitInfoSet);
		        
		        request.setAttribute("fildOptionMap", fildOptionMap);
		        request.setAttribute("searchRcd", searchRcd);
		        request.setAttribute("provinceSet", provinceSet);
		        request.setAttribute("provinceMap", provinceMap);
				forward("/back/infoRecommend/UnitRecommend.jsp");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (ServletException e) {
			e.printStackTrace();
		}
    }
	
    
    
    
    /**
     * 科研单位推荐
     * 
     * @param request
     * @param response
     */
    public void changeUnitStatus(HttpServletRequest request,
        HttpServletResponse response)
    {
		RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
		InfoRecommendHandler infoRecommhandler = new InfoRecommendHandler();
        infoRecommhandler.changeUnitStatus(requestKit);
    }
    
}
